#include <iostream>
using namespace std;
int main()
{
    int k;
    int st, ed, s, e;
    int a[10000];
    int i;
    cin >> k;
    for (i = 0; i < k; i++)
    {
        cin >> a[i];
    }
    int max, count;
    i = 0;
    while (i < k && a[i] < 0)
        i++;
    if (i == k)
    {
        cout << 0 << " " << a[0] << " " << a[k - 1];
        return 0;
    }
    count = max = a[i];
    s = st = ed = i;
    for (i = i + 1; i < k; i++)
    {
        count += a[i];
        e = i;
        if (count > max)
        {
            max = count;
            st = s;
            ed = e;
        }
        else if (count < 0)
        {
            count = 0;
            s = e = i + 1;
        }
    }
    cout << max << ' ' << a[st] << ' ' << a[ed];
    return 0;
}